function setCookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	if(cookieValue == '' || seconds < 0) {
		cookieValue = '';
		seconds = -2592000;
	}
	expires.setTime(expires.getTime() + seconds * 1000);
	domain = COOKIE_DOMAIN;
	path = COOKIE_PATH;
	document.cookie = escape(COOKIE_PRE + cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

function getCookie(name)
{
	 var arr,reg=new RegExp("(^| )"+COOKIE_PRE+name+"=([^;]*)(;|$)");
	 if(arr=document.cookie.match(reg))
	  return unescape(arr[2]);
	 else
	  return false;
}

function delCookie(name)
{
	 var exp = new Date();
	 exp.setTime(exp.getTime() - 10000);
	 document.cookie= name + "=0;expires="+exp.toGMTString()+";path="+COOKIE_PATH+";domain="+COOKIE_DOMAIN;
}
function activeemail(url) {
	$.get(url,{},function(msg) {
		if (msg == '2') {
			alert('再次邮件发送间隔不能少于10分钟');
		} else if (msg == '3') {
			alert('系统错误，发送邮件失败，请联系管理员！');
		} else if (msg == '1' ) {
			alert('激活邮件已经发送到您的注册邮箱中，请查收.');
		} else if (msg == '4' ) {
			alert('你的账号已经激活.');
		}else {
			alert('你未登录');
		}
	});
}
function check_email(id){
	var reEml = /^[\w\-\.]+@[a-z0-9]+(\-[a-z0-9]+)?(\.[a-z0-9]+(\-[a-z0-9]+)?)*\.[a-z]{2,4}$/i;   
	if(reEml.test(document.getElementById(id).value)){
		return true;
	}else{
		alert('邮箱地址不合法');
		return false;
	}
}
function check_username(id){
	if(document.getElementById(id).value.length>1) {
		return true;
	}else{
		alert('用户名不正确');
		return false;
	}
//	$.get('admin.php','m=user&f=ajax_check_username&username='+encodeURIComponent(username),function(msg) {
//		if (msg == 'success') {
//			$('#msg_username').html('<font color="green">可用</font>');
//			$('#save_user').removeAttr('disabled');
//		} else if (msg == 'error') {
//			$('#msg_username').html('<font color="red">该用户名已经被使用</font>');
//			$('#save_user').attr('disabled','disabled');
//		}
//	});	
}
function resize_img(img) {
	var maxwidth = typeof(image_resize_width)!='undefined' ? image_resize_width : 1030;
	if (img.width > maxwidth) {
		//img.style.width = maxwidth+"px";
		img.style.cursor = 'pointer';
		img.alt = '点击查看原图';
		img.style.width="1030px";
		img.onclick = function() {
			window.open(img.src);
		}
	}
}
function insert_attach(val){
	editor.insertHtml(val);
}
function article_password(aid){
	var passwd = $("input[@name='passwd"+aid+"']").val();
	if (passwd == '') {
		alert('请输入密码！');
	} else {
		$(":submit[@name='submit"+aid+"']").attr('disabled','disabled').val('检测中...');
		var data = 'id='+aid+'&passwd='+encodeURIComponent(passwd);
		$.post('article.php?f=check_passwd', data, function (msg) {
			eval("var message = "+msg);
			$(":submit[@name='submit"+aid+"']").removeAttr('disabled').val('提交');
			if (message.type == 'error') {
				$('#errormsg').html('<font color="red">密码错误!</font> ');
			} else if (message.type == 'success') {
				$(".content").html(message.data);
			}
		});
	}
}
/*构造日期选择器
 * d -- 天id
 * y -- 年 id
 * m -- 月id
 * et: makeday('choiceday','choiceyear','choicemonth')
 */

function makeday(d,y,m){
	var dobj =  document.getElementById(d);//$('#'+d);
	var mobj = document.getElementById(m);
	var yobj = document.getElementById(y);
	var birthday = dobj.value;
	dobj.length=0;
	dobj.options.add(new Option('日', ''));
	for(var i=0;i<28;i++){
		dobj.options.add(new Option(i+1, i+1));
	}
	if(mobj.value!="2"){
		dobj.options.add(new Option(29, 29));
		dobj.options.add(new Option(30, 30));
		switch(mobj.value){
			case "1":
			case "3":
			case "5":
			case "7":
			case "8":
			case "10":
			case "12":{
				dobj.options.add(new Option(31, 31));
			}
		}
	} else if(yobj.value!="") {
		var nbirthyear=yobj.value;
		if(nbirthyear%400==0 || (nbirthyear%4==0 && nbirthyear%100!=0)) dobj.options.add(new Option(29, 29));
	}
	dobj.value = birthday;
}

function getregion(obj,id){
	var regionobj = document.getElementById(id);
	regionobj.length=0;
	if(obj.value<2){
		regionobj.options.add(new Option('请选择地区', '0'));
	}else{
		var region=Array();region[5]=Array();region[6]=Array();region[7]=Array();region[8]=Array();
		region[5][11]='文化宫';region[5][12]='青山桥';
		region[6][21]='南大街';region[6][22]='北大街';
		region[7][41]='恐龙园';region[7][42]='长江贸易中心';
		region[8][61]='大学城';region[8][62]='湖塘乐购';
		for(var k in region[obj.value]){
			regionobj.options.add(new Option(region[obj.value][k], k));
		}
	}
	
}
function ajax_post_comment () {
	var username = $.trim($('#username').val());
	var email = $.trim($('#email').val());
	var homepage = $.trim($('#homepage').val());
	var content = $.trim($('#content').val());
	var vdcode = $('#vdcode').val();
	var hide = $('#hide').attr('checked') ? 1 : 0;
	var isuser = $('#isuser').val();
	if (!isuser) {
		if (username == '') {
			$('#tip_username').css('color','red'); $('#tip_username').html('请输入你的名称');
			return false;
		} else {
			$('#tip_username').css('color','green'); $('#tip_username').html('正确');
		}
		
		if (email == '') {
			$('#tip_email').css('color','red'); $('#tip_email').html('请输入你的邮箱地址，我们会替你保密');
			return false;
		} else {
			var emailReg=/^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
			if (!emailReg.test(email)) {
				$('#tip_email').css('color','red'); $('#tip_email').html('你输入的邮箱地址格式有误');
				return false;
			} else {
				$('#tip_email').css('color','green'); $('#tip_email').html('正确');
			}
		}
		if (homepage != '' && homepage.indexOf('http://') == -1) {
			$('#tip_homepage').css('color','red'); $('#tip_homepage').html('你的网址不合法，别忘了加上http://');
			return false;
		} else {
			$('#tip_homepage').css('color','green'); $('#tip_homepage').html('正确');
		}
	}
	if (content == '') {
		$('#tip_content').css('color','red'); $('#tip_content').html('别忘了输入内容');
		return false;
	} else {
		$('#tip_content').html('');
	}
	if (vdcode != undefined) {
		if (vdcode == '') {
			$('#tip_vdcode').css('color','red'); $('#tip_vdcode').html('请输入验证码');
			return false;
		} else {
			$('#tip_vdcode').html('');
		}
	}
	var btn_str = $('#submit').val();
	$('#submit').attr('disabled','disabled');
	$('#submit').val('正在提交...');
	var data = 'shopid='+$('#shopid').val()+'&type='+$('#type').val()+'&aid='+$('#aid').val()+'&ajax=1&pid='+$('#pid').val()+'&username='+encodeURIComponent(username)+'&email='+encodeURIComponent(email)+'&homepage='+encodeURIComponent(homepage)+'&content='+encodeURIComponent(content)+'&hide='+hide+'&vdcode='+encodeURIComponent(vdcode);
	$.ajax({
		type : 'POST',
		url : $('#post_comment').attr('action'),
		data : data,
		cache : false,
		success : function (msg) {
			eval("var message = " + msg);
			if (message.type == 'success') {
				if(message.pid > 0){
					$('#comment-'+message.pid+' .comment_content').append(message.data);
				}else{
					$('#comment_list').append(message.data);
				}
				$('#content').val('');
				$('#submit').removeAttr('disabled');
				$('#submit').val(btn_str);
				cancel_replay();
			} else {
				alert("出错了：\n\n"+message.data);
				$('#submit').removeAttr('disabled');
				$('#submit').val(btn_str);
			}
		}
	});
	return false;
}
function confirm_delete() {
	if(!confirm('确定删除？')) return false;
	return true;
}
function reply_comment(id) {
	$("#pid").val(id);
	$('#post-comment-title').show().attr('onclick','cancel_replay()');
	var reply = '<div class="post_comment">'+$('.post_comment').html()+'</div>';
	$('.post_comment').remove();
	$('#comment-'+id).append(reply);
}
function cancel_replay() {
	$("#pid").val(0);
	$('#post-comment-title').hide();
	var reply = '<div class="post_comment">'+$('.post_comment').html()+'</div>';
	$('.post_comment').remove();
	$('#comment-0').append(reply);
}
function setCopy(text) {
	 if (window.clipboardData) {
		    window.clipboardData.setData("Text", text);
			alert("已经成功复制到剪贴板！");
		  } else {
			var x=prompt('你的浏览器不支持自动复制,请你手动复制下面的地址(Ctrl+C)：',text);
		  }
	}
function money(s,n)  
{
	if(typeof(n) =='undefined' || n<1)var n=2;
   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";  
   var l = s.split(".")[0].split("").reverse(),  
   r = s.split(".")[1];  
   t = "";  
   for(i = 0; i < l.length; i ++ )  
   {  
      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
   }
   if(isNaN(t)) return '';
   return t.split("").reverse().join("") + "." + r;  
} 
$(function() {
	if(getCookie('msg')) {
		var msg = decodeURI(getCookie('msg'));
		setCookie('msg','');
		$('<div class="sucmsg">'+msg+'</div>').insertBefore($('#uc_contain'));
		setTimeout("$('.sucmsg').fadeOut(1000)",3000);
	}
});
//模拟打开链接
function CreateA(url){
    var vra=document.createElement('a');
    vra.target='_blank';
    vra.href=url;
    document.body.appendChild(vra);
    vra.click();
}
//滚动new simplescroll('jinpairesutl', {start_delay:0, speed: 40, delay:2000, direction:1, scrollItemCount:1, movecount:1});
function simplescroll(C,A){
	this.config=A?A:{start_delay:0,speed:23,delay:3000,direction:1,scrollItemCount:1,movecount:1};
	this.container=document.getElementById(C);
	this.pause=false;
	var B=this;
	this.init=function(){
		var H=B.container;
		B.scrollTimeId=null;
		if(B.config.direction==2||B.config.direction==4){
			var G=document.createElement("div");
			var F=H.getElementsByTagName("li").length;
			var D=H.getElementsByTagName("li")[0].offsetWidth;
			var E=H.getElementsByTagName("li")[0].offsetHeight;
			G.innerHTML=H.innerHTML;
			H.innerHTML="";
			G.style.width=F*D+"px";
			H.appendChild(G);
		}
		setTimeout(B.start,B.config.start_delay);
	}; 
	this.start=function(){
		var F=B.container;
		if(B.config.direction==1||B.config.direction==3){
			var E=F.getElementsByTagName("li")[0].offsetHeight;
//			if(F.scrollHeight-F.offsetHeight>=E){
				B.scrollTimeId=setInterval(B.scroll,B.config.speed);
//			}
		}else{
			if(B.config.direction==2){
				F.scrollLeft=F.scrollWidth;
				var D=F.getElementsByTagName("li")[0].offsetWidth;
				B.scrollTimeId=setInterval(B.scroll,B.config.speed);
			}else{
				if(B.config.direction==4){
					var D=F.getElementsByTagName("li")[0].offsetWidth;
					B.scrollTimeId=setInterval(B.scroll,B.config.speed);
				}
			}
		}
	};
	this.scroll=function(){
		if(B.pause){return false;}
		var G=B.container;
		switch(B.config.direction){
			case 1:
				G.scrollTop+=2;
				var F=G.getElementsByTagName("li")[0].offsetHeight;
				if(G.scrollTop%(F*B.config.scrollItemCount)<=1){
					if(B.config.movecount!=undefined){
						for(var E=0;E<B.config.movecount;E++){
							G.appendChild(G.getElementsByTagName("li")[0]);
						}
					}else{
						for(var E=0;E<B.config.scrollItemCount;E++){
							G.appendChild(G.getElementsByTagName("li")[0]);
						}
					}
					G.scrollTop=0;
					clearInterval(B.scrollTimeId);
					setTimeout(B.start,B.config.delay);
				}
			break;
			case 4:
				G.scrollLeft+=2;
				var D=G.childNodes[0].getElementsByTagName("li")[0].offsetWidth;
				if(G.scrollLeft%(D*B.config.scrollItemCount)<=1){
					if(B.config.movecount!=undefined){
						for(var E=0;E<B.config.movecount;E++){
							G.childNodes[0].appendChild(G.childNodes[0].getElementsByTagName("li")[0]);
						}
					}else{
						for(var E=0;E<B.config.scrollItemCount;E++){
							G.childNodes[0].appendChild(G.childNodes[0].getElementsByTagName("li")[0]);
						}
					}
					G.scrollLeft=0;
					clearInterval(B.scrollTimeId);
					setTimeout(B.start,B.config.delay);
				}
				break
		}
	};
	this.container.onmouseover=function(){
		B.pause=true
	};
	this.container.onmouseout=function(){
		B.pause=false
	};
	this.init();
}
function del_attach(id) {
	if(!confirm('确定删除？')) return false;
	if(id){
		$.getJSON('home.php?m=upload&f=delete&id='+id+'&tm='+Math.random(),'',function(data){
			if(data.s==true){
				$('#tr_'+id).remove();
			}else{
			}
		});
	}
}